package com.bjsxt.service.imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bjsxt.commons.DataGridModel;
import com.bjsxt.mapper.StaffMapper;
import com.bjsxt.pojo.Staff;
import com.bjsxt.pojo.StaffExample;
import com.bjsxt.pojo.UsersExample;
import com.bjsxt.service.EmployeesService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
/**
 * 对于员工的所有业务操作
 * @author 程应康
 *
 */
@Service
public class EmployeesServiceImpl implements EmployeesService {
	@Autowired
	private StaffMapper staffMapper;
	@Override
	public DataGridModel findEmployees(Integer page, Integer rows) {
		PageHelper.startPage(page, rows);
		StaffExample example = new StaffExample();
		List<Staff> staffs = staffMapper.selectByExample(example);
		//总条数的获取
		PageInfo<Staff> ps = new PageInfo<>(staffs);
		long total = ps.getTotal();
		
		DataGridModel gm = new DataGridModel();
		gm.setRows(staffs);
		gm.setTotal(total);
		
		return gm;
	}
	
	@Override
	public void addEmployees(Staff staff) throws Exception{
		staffMapper.insertSelective(staff);
	}
	
	@Override
	public void dropEmployees(Integer staffid) throws Exception {
		staffMapper.deleteByPrimaryKey(staffid);
	}

	@Override
	public void modifyEmployees(Staff staff) throws Exception {
		staffMapper.updateByPrimaryKeySelective(staff);
	}

}
